﻿using System;
using System.Collections.Generic;
using Dsl.Ped.Framework.Helpers;
using NUnit.Framework;

namespace DSLPedFrameworkTest.Helpers {

    [TestFixture]
    public class HashingHelperTest {

        [System.SerializableAttribute()]
        public class TestingObjectA
        {
            public TestingObjectA(int number)
            {
                B = new TestingObjectB {B_Property = number};
            }

            public TestingObjectB B { get; set; }
        }

        [System.SerializableAttribute()]
        public class TestingObjectB
        {
            private int x = 0;

            public int B_Property { get; set; }

            public List<TestingObjectC> List = new List<TestingObjectC>()
                                           {new TestingObjectC {Y = "ahoj"}, new TestingObjectC {Y = "hello "}};

            public List<DateTime> DateTimes = new List<DateTime>() {new DateTime(2000, 10, 5)};

            public void SetX(int x)
            {
                this.x = x;
            }
        }

        [System.SerializableAttribute()]
        public class TestingObjectC
        {
            public string Y { get; set; }
        }

        [SetUp]
        public void SetUp() {
        }

        [Test]
        public void GetHashTest1() {

            int x = 10;
            string result = HashingHelper.GetHash(x);
            Assert.IsNotNullOrEmpty(result);
        }

        [Test]
        public void GetHashTest2()
        {
            var testingObjectA = new TestingObjectA(5);
            var hash1 = HashingHelper.GetHash(testingObjectA);

            testingObjectA.B.B_Property = 6;
            var hash2 = HashingHelper.GetHash(testingObjectA);

            Assert.AreNotEqual(hash1, hash2);
        }

        [Test]
        public void GetHashTest3() {
            var testingObjectA = new TestingObjectA(5);
            var hash1 = HashingHelper.GetHash(testingObjectA);

            testingObjectA.B.SetX(1000);
            var hash2 = HashingHelper.GetHash(testingObjectA);

            Assert.AreNotEqual(hash1, hash2);
        }

        [Test]
        public void GetHashTest4() {
            var testingObjectA = new TestingObjectA(5);
            var hash1 = HashingHelper.GetHash(testingObjectA);

            testingObjectA.B.List[0].Y = "hello";
            var hash2 = HashingHelper.GetHash(testingObjectA);

            Assert.AreNotEqual(hash1, hash2);
        }

        [Test]
        public void GetHashTest5() {
            var testingObjectA = new TestingObjectA(5);
            var hash1 = HashingHelper.GetHash(testingObjectA);

            testingObjectA.B.DateTimes[0] = new DateTime(1999,10,5);
            var hash2 = HashingHelper.GetHash(testingObjectA);

            Assert.AreNotEqual(hash1, hash2);
        }
    }
}
